package com.jianyi.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;

import com.jianyi.base.BaseController;

public class LoginController extends BaseController{

	public void index(){
		
		String username=getPara("username");
		String password=getPara("password");
		
		String error = null;
		Subject subject = SecurityUtils.getSubject();
		UsernamePasswordToken token =
		new UsernamePasswordToken(username, password);
		
		try {
			subject.login(token);
		} catch (UnknownAccountException e) {
			error = "用户名/密码错误";
		} catch (IncorrectCredentialsException e) {
			error = "用户名/密码错误";
		} catch (AuthenticationException e) {
			// 其他错误，比如锁定，如果想单独处理请单独catch 处理
			error = "其他错误：" + e.getMessage();
		}
		
		if(error!=null){
			System.out.println("用户密码错误！");
		}else{
			System.out.println("用户密码正确！");
		}
		
		renderText("ceee");
	}
	
	public void ggg(){
		
		renderText("ggg");
	}
}
